<?php

namespace catchAdmin\stock\model;

use catcher\base\CatchModel;
use think\facade\Db;
use think\Model;
use catcher\traits\db\BaseOptionsTrait;
use catcher\traits\db\ScopeTrait;
/**
 *
 * @property int $id
 * @property string $warehouse_out_id
 * @property string $warehouse_out_son_id
 * @property string $pick_id
 * @property string $tray_id
 * @property string $box_id
 * @property string $slice_id
 * @property int $number
 * @property string $status
 * @property int $auth_id
 * @property int $creator_id
 * @property int $updated_at
 * @property int $created_at
 * @property int $deleted_at
 * @property int $tenant_id
 */
class Pick extends CatchModel
{
    use BaseOptionsTrait, ScopeTrait;
    
    public $field = [
        // ID
        'id',
        // 出库主单编号
        'warehouse_out_id',
        // 出库明细编号
        'warehouse_out_son_id',
        // 拣货编号
        'pick_id',
        // 托盘码
        'tray_id',
        // 箱号
        'box_id',
        // 片号
        'slice_id',
        // 拣货数量
        'number',
        // 出库状态:0=未出库,1=出库,
        'status',
        // 出库人
        'auth_id',
        // 拣货人
        'creator_id',
        // 更新时间（出库时间）
        'updated_at',
        // 创建时间
        'created_at',
        // 删除时间
        'deleted_at',
        // 商户
        'tenant_id',
        'stock_id',
        'pick_no',
        'LOT1',
        'LOT2',
        'LOT3',
        'sn'
    ];
    
    public $name = 'db_pick';

    public function getListByClientGnamePid($project_client,$goods_name,$packing_id){
        $field = "p.*";

        $where=[];
        $where[] = ['w.project_client','=',$project_client];
        $where[] = ['ws.goods_name','=',$goods_name];
        $where[] = ['ws.packing_id','=',$packing_id];
        $where[] = ['p.deleted_at','=',0];
        $where[] = ['p.status','=',0];

        $list = $this->catchSearch()
            ->alias('p')
            ->field($field)
            ->leftJoin('db_warehouse_out_son ws','p.warehouse_out_son_id = ws.warehouse_out_son_id')
            ->leftJoin('db_warehouse_out w','w.warehouse_out_id = ws.warehouse_out_id')
            ->where($where)
            ->select()->toArray();

        return $list;
    }

}